package pojo;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class WSConstants {

	public final static String SAP_WS_AMOEBA_SYSID = "AMB";
	public final static String SAP_REQUEST_PARAM_TEMPLATE = "<?xml version = \"1.0\"?><Body><TableInfo><RowInfo><BEDAT1>#PARAM1#</BEDAT1><BEDAT2>#PARAM2#</BEDAT2></RowInfo></TableInfo> </Body>";
	public final static String SAP_REQUEST_PARAM_TEMPLATE2 = "<?xml version = \"1.0\"?><Body><TableInfo><RowInfo><BEDAT1>#PARAM1#</BEDAT1><BEDAT2>#PARAM2#</BEDAT2><CODE>#PARAM3#</CODE></RowInfo></TableInfo> </Body>";
	// 销售单和转移单专用参数
	public final static String SAP_REQUEST_PARAM_TEMPLATE3 = "<?xml version = \"1.0\"?><Body><TableInfo><RowInfo><DATE_B>#PARAM1#</DATE_B><DATE_E>#PARAM2#</DATE_E></RowInfo></TableInfo> </Body>";
	public final static String DATE_FORMAT = "yyyyMMdd";
	public final static String EMPTY_DATE = "00000000";
	public final static String SALES_RE_BILL_CODE = "RE"; // 退货单单据类型
	public final static String SALES_SV_BILL_TYPE_SAP = "ZSV"; // 三包理赔销售单类型
	public final static String SALES_S9_BILL_TYPE_SAP = "ZS9"; // S9类型的销售单类型，展销？可排除
	public final static String SALES_SV_BILL_TYPE_AMOEBA = "SV"; // 三包理赔销售单类型
	public final static String SALES_SO_BILL_TYPE_AMOEBA = "SO"; // 普通销售单类型
	
	
	public final static String PURCHASE_BILL_BACK_CODE = "102"; // 采购单收货冲销物料移动类型
	public final static String PURCHASE_BILL_RE_CODE = "161"; // 采购单退货物料移动类型
	
	public final static String PARAM_CODE_PURCHASE = "A"; // 采购收货单的参数编码
	public final static String PARAM_CODE_DD = "B"; // 调拨单的参数编码（比如车间之间）
	public final static String PARAM_CODE_LL = "C"; // 领料单的参数编码（比如车间和原材料采购部库位）
	public final static String PARAM_CODE_ALL = "D"; // 物料出入库数据的参数编码
	
	public final static String OUT_MARK = "H";  // SAP出库标识
	public final static String IN_MARK = "S"; // SAP入库标识
	
	public final static String INNER_CUSTOMER_START = "5";
	public final static String OUTER_CUSTOMER_START = "6";
	public final static String INNER_CUSTOMER_REMARK = "国内销售暂估";
	public final static String OUTER_CUSTOMER_REMARK = "出口销售暂估";
	public final static String OUTER_HK_START = "64"; // 部分外销需途径香港的订单对应的客户编码的前缀，这部分外销单据的订单单价需使用对应合同的参考价而不是实际订单的单价
	
	public final static String SD_COMPANY_CODE = "2100"; // 浦林成山（山东）轮胎有限公司
	public final static String HK_COMPANY_CODE = "2000"; // 浦林成山（香港）轮胎有限公司
	public final static String TL_COMPANY_CODE = "2170"; // 浦林成山（泰国）轮胎有限公司
	
	public final static String MATERIAL_CODE_BPBJ_START = "S"; // 备品备件类商品的编码开头
	public final static String MATERIAL_CODE_HUAXUEYONGPIN_START = "X"; // 化学用品类商品的编码开头
	
	public final static String ADJUST_STOCK_BILL_TYPE = "Z61";   // 月末库存盘点调整的物料移动类型
	public final static String ADJUST_STOCK_BILL_TYPE_R = "Z62"; // 月末库存盘点调整的物料移动类型的逆操作
	
	public final static String AUTO_BILL = "X"; // 自动生成单据标识
	
	// 财务科目同步常量
	public final static String FINANCE_SUBJECT_ZINTNO = "INT_AMB010"; 
	
	// 销售订单
	public final static String SALES_ORDER_ZINTNO = "INT_AMB017"; 
		
	// 转移单
	public final static String TRANSFER_BILL_ZINTNO = "INT_AMB016"; 
	
	// 客户数据同步
	public final static String CUSTOMER_ZINTNO = "INT_AMB007"; 
	
	// 半成品重量数据同步
	public final static String SEMI_PRODUCT_WEIGHT_ZINTNO = "INT_AMB003"; 
	
	// 完工单数据同步
	public final static String COMPLETE_BILL_ZINTNO = "INT_AMB014"; 
	
	// 物料出入库数据同步 (通过配合 CODE 参数  A B C D 来获取采购收货单，调拨单，领料单，和所有物料出入库单据)
	public final static String INOUT_BILL_ZINTNO = "INT_AMB012"; 
	
	// 物料品项数据同步
	public final static String MATERIAL_ZINTNO = "INT_AMB001"; 
	
	// 财务科目费用 (日月)
	public final static String FINANCE_COST_ZINTNO = "INT_AMB008"; 
	
	// 产成品入库单
	public final static String WAREHOUSE_IN_ZINTNO = "INT_AMB015"; 
	
	// 设备资产 & 房屋建筑物
	public final static String ASSET_ZINTNO = "INT_AMB004"; 
	
	
	public static String constructRequestParam(String param1, String param2) {
		return SAP_REQUEST_PARAM_TEMPLATE.replace("#PARAM1#", param1).replace("#PARAM2#", param2);
	}
	
	public static String constructRequestParam2(String param1, String param2, String param3) {
		return SAP_REQUEST_PARAM_TEMPLATE2.replace("#PARAM1#", param1).replace("#PARAM2#", param2).replace("#PARAM3#", param3);
	}
	
	public static String constructRequestParam3(String param1, String param2) {
		return SAP_REQUEST_PARAM_TEMPLATE3.replace("#PARAM1#", param1).replace("#PARAM2#", param2);
	}
	
	public static Date parseDateString(String dateString) {
		if(null == dateString || "".equals(dateString.trim()) || EMPTY_DATE.equals(dateString.trim())) {
			return null;
		}
		Date result = null;
		DateFormat formatter = new SimpleDateFormat(DATE_FORMAT);
		try {
			result = formatter.parse(dateString);
		}catch(Exception e) {
			e.printStackTrace();
			result = null;
		}
		return result;
	}
	
	public static Double parseDoubleString(String doubleString) {
		Double result = new Double(0);
		if(null == doubleString || "".equals(doubleString.trim())) {
			return result;
		}
		try {
			result = Double.parseDouble(doubleString);
		}catch(Exception e) {
			e.printStackTrace();
			result = new Double(0);
		}
		return result;
		
	}
	
	public static boolean compareString(String s1, String s2) {
		if(null == s1 && null == s2) {
			return true;
		}
		if(null == s1 && null != s2) {
			return false;
		}
		if(null != s1 && null == s2) {
			return false;
		}
		
		return s1.equalsIgnoreCase(s2);
	}
	
}
